/**
 * 
 * Opened Touchable RIA Framework - A Web RIA Javascript Framework
 * 
 * Copyright (c) 2012
 * Dual licensed under the MIT or GPL v2 licenses.
 * 
 * @author  CuTe_CuBe
 * @version $Id: vml.js 8 2012-03-11 14:16:41Z cc.hgfeng@gmail.com $
 */

/**
 * OTR.Graph
 * VML 绘图接口实现
 * 
 */
OTR.Graph.Vml = OTR.extend(OTR.Graph.Adapter, {
    
    /**
     * 初始化绘图对象
     * 
     * @param object params
     */
    init: function(config) {
        if (!OTR.Util.isObject(config)) {
            //throw 'Invalid params';
        }
        
        this._setType('Vml');
        this._ns   = 'ortv';
        this._cfgs = {
            width: 100,
            height: 100,
            doc: document
        };
        
        var cssText = ['position:relative;display:block'];
        for (var k in config) {
            if (undefined !== this._cfgs) {
                this._cfgs[k] = config[k];
                
                if (k == 'width' || k == 'height') {
                    cssText[cssText.length] = k + ':' + config[k] + 'px';
                }
            }
        }
        
        var doc = this._cfgs.doc;
        
        if (OTR.Client.version('8.0') == 0) {
            doc.namespaces.add(this._ns, "urn:schemas-microsoft-com:vml", "behavior: url(#default#VML);display:block");
        } else {
            doc.namespaces.add(this._ns, "urn:schemas-microsoft-com:vml");
            
            var style = doc.createElement('style');
            
            var fc = doc.documentElement.firstChild;
            fc.appendChild(style);

            if (style.styleSheet) {
                style.styleSheet.addRule(this._ns + "\\:*", "{behavior: url(#default#VML);display:inline-block}");
            }
        }
        
        this._canvas = this._cfgs.doc.createElement(this._ns + ':group');
        this._canvas.coordsize = this._cfgs.width + ',' + this._cfgs.height;
        this._canvas.style.cssText = cssText.join(';');
        
        this._list = [];
    },

    /**
     * 绘制文字
     * 
     * @param string text 
     * @param mixed  size
     * @param int    x
     * @param int    y
     * @param string font
     * @return OTR.Graph.Adapter
     */
    drawText: function(text, size, x, y, font) {},
    
    /**
     * 插入图片
     * 
     * @param string src
     * @param int   width
     * @param int   height
     * @param int   x
     * @param int   y
     * @return OTR.Graph.Adapter
     */
    drawImage: function(src, width, height, x, y) {},
    
    /**
     * 获取原点绝对坐标
     * 
     * @return object
     */
    getOrigin: function() {
        return {
            x: this._canvas.offsetLeft,
            y: this._canvas.offsetTop
        };
    },
    
    /**
     * 获取当前vml绘图对象所在document
     * 
     * @return HTMLDocument
     */
    getDoc: function() {
        return this._cfgs.doc;
    },
    
    /**
     * 获取命名空间
     * 
     * @return string
     * @returns {String}
     */
    getNs: function() {
        return this._ns;
    }
});
